package com.wwinsoft.framework.web.system.Taglib;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;

public class StringDisplayTag extends BodyTagSupport {
    private final Log logger = LogFactory.getLog(getClass());

    private int length=10;
    private String fullText;
    private String clickEvent;
    
	public int getLength() {
		return length;
	}

	public void setLength(int length) {
		this.length = length;
	}

	public String getFullText() {
		return fullText;
	}

	public void setFullText(String fullText) throws JspException {
        this.fullText = (String) ExpressionEvaluatorManager.evaluate("fullText", fullText, String.class,
                                                                              this,
                                                                              pageContext);
	}

	public StringDisplayTag(){
    }

    private String getShortString(){
    	if(fullText==null)
    		return "";
    	if(fullText.length()<=this.length)
    		return fullText;
    	else
    		return fullText.substring(0, this.length);
    }
    
    public int doStartTag() throws JspException {
		JspWriter out = pageContext.getOut();
		StringBuffer html = new StringBuffer("");
		if(fullText.length()<=this.length){
            html.append(fullText);
		}else{
            html.append("<acronym title=\"");
            html.append(fullText);
            html.append( "\">");
            html.append(getShortString());
            html.append("</acronym>");
		}
		try {
			out.println(html.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
        return super.doStartTag();
    }
    
}
